// Variables used for example purposes only
long lastMillis = 0;
long sequenceTime  =  1000;
int  metro = 1;
boolean sequenceOn = false;

// Define the COM port used
String XBEE_PORT = "COM60";

// Define the Nodes in the network in the Nodes Tab
// Handle the incoming messages in the Function Table Tab

void setup() {
  size(255,255);
  setupXBee(); 
  initNodes();
}


void draw() {
  background(0);  
  checkXBee();
  if(sequenceOn){ sequence(); }
}

void sequence()
{
  if( millis() > lastMillis + sequenceTime )
  {
    message.setFunction(0);
    message.setScope("BO404");
    message.setReceiver("BROADCAST");
    message.addArgument(metro);
    sendToXBee(message); 
    println("SEQUENCING: " + metro);
    
    metro++;
    if(metro > 4){ metro = 1; }
    lastMillis = millis();
  }
}

void mousePressed() {
  // Send a function 0 to Node "NODE 1" with two arguments; x and y
  message.setFunction(0);
  message.setReceiver("NODE 1");
  message.setScope("HG4.05");
  message.addArgument(mouseX);
  message.addArgument(mouseY);
  sendToXBee(message);
}

void keyPressed()
{
  sequenceOn = !sequenceOn;
}
